local hx__chuifeng = fk.CreateSkill {
  name = "hx__chuifeng",
}

hx__chuifeng:addEffect("viewas", {
  anim_type = "offensive",
  prompt = "#hx__chuifeng",
  times = function(self, player)
    return player.phase == Player.Play and 2 - player:usedSkillTimes(hx__chuifeng.name, Player.HistoryPhase) or -1
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, player, cards)
    local card = Fk:cloneCard("duel")
    card.skillName = hx__chuifeng.name
    return card
  end,
  before_use = function(self, player, use)
    use.extra_data = use.extra_data or {}
    use.extra_data.hx__chuifeng = player
    player.room:loseHp(player, 1, hx__chuifeng.name)
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(hx__chuifeng.name, Player.HistoryPhase) < 2 and player.hp > 0
  end,
})

hx__chuifeng:addEffect(fk.DamageInflicted, {
  anim_type = "defensive",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    if target == player and data.card and table.contains(data.card.skillNames, hx__chuifeng.name) then
      local use_event = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      return use_event and (use_event.data.extra_data or {}).hx__chuifeng == player
    end
  end,
  on_use = function(self, event, target, player, data)
    data:preventDamage()
    player.room:invalidateSkill(player, "hx__chuifeng", "-phase")
  end,
})

return hx__chuifeng 